package com.imooc.mq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liansen
 * @create 03-15-19:46
 */
@Configuration
public class InitResumeMQConfig {

    //交换机名称 大小写转换键: 选中后: ctrl + shift + u
    public static final String INIT_RESUME_EXCHANGE = "init_resume_exchange";

    //队列名称
    public static final String INIT_RESUME_QUEUE = "init_resume_queue";

    //交换机和队列绑定的路由键
    public static final String INIT_RESUME_ROUTINGKEY = "init.resume.display";

    //创建通配符模式的交换机
    @Bean(INIT_RESUME_EXCHANGE)
    public Exchange exchange(){
        return ExchangeBuilder.topicExchange(INIT_RESUME_EXCHANGE)
                                .durable(true)
                                .build();
    }

    //创建队列
    @Bean(INIT_RESUME_QUEUE)
    public Queue queue(){
        return QueueBuilder.durable(INIT_RESUME_QUEUE).build();
    }

    //创建交换机和队列的绑定关系
    @Bean
    public Binding initResumeBinding(){
        /**
         * String destination, 目的地名称
         * DestinationType destinationType, 目的地类型
         * String exchange, 交换机
         * String routingKey, 路由键  #代表0或多个单词, *代表一个单词
         * @Nullable Map<String, Object> arguments 参数
         */
        return new Binding(INIT_RESUME_QUEUE,
                Binding.DestinationType.QUEUE,
                INIT_RESUME_EXCHANGE,
                "init.resume.#",
                null);
    }
}
